/*     */ package nccloud.web.mmsfc.operationrep.action;
/*     */ 
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import nc.itf.mmpac.dmo.IDmoQueryService;
/*     */ import nc.itf.uap.pf.IPfExchangeService;
/*     */ import nc.util.mmf.framework.base.MMValueCheck;
/*     */ import nc.vo.mm.mmsfc.vochange.TransBillCommonProcess;
/*     */ import nc.vo.mmpac.dmo.entity.AggDmoVO;
/*     */ import nc.vo.mmpac.dmo.entity.DmoProcedureVO;
/*     */ import nc.vo.mmpac.dmo.entity.DmoVO;
/*     */ import nc.vo.mmsfc.operationrep.entity.AggOprepVO;
/*     */ import nc.vo.mmsfc.operationrep.util.DefaultBillUtil;
/*     */ import nc.vo.pub.BusinessException;
/*     */ import nc.vo.pub.CircularlyAccessibleValueObject;
/*     */ import nc.vo.pub.lang.UFDateTime;
/*     */ import nccloud.framework.core.exception.ExceptionUtils;
/*     */ import nccloud.framework.core.json.IJson;
/*     */ import nccloud.framework.service.ServiceLocator;
/*     */ import nccloud.framework.web.action.itf.ICommonAction;
/*     */ import nccloud.framework.web.container.IRequest;
/*     */ import nccloud.framework.web.json.JsonFactory;
/*     */ import nccloud.framework.web.ui.model.row.Cell;
/*     */ import nccloud.framework.web.ui.model.row.Row;
/*     */ import nccloud.framework.web.ui.pattern.billgrid.BillGrid;
/*     */ import nccloud.framework.web.ui.pattern.billgrid.BillGridOperator;
/*     */ import nccloud.framework.web.ui.pattern.grid.Grid;
/*     */ import nccloud.mmpac.applytask.pub.entity.PkTsVODTO;
/*     */ import nccloud.mmpac.applytask.pub.entity.TransferData;
/*     */ import nccloud.mmpac.applytask.pub.entity.TransferInfo;
/*     */ import nccloud.web.mmsfc.operationrep.util.OprepScaleUtil;
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TransFromDmoAction
/*     */   implements ICommonAction
/*     */ {
/*     */   public Object doAction(IRequest request) {
/*  42 */     BillGrid[] grids = null;
/*     */     try {
/*  44 */       String read = request.read();
/*  45 */       IJson json = JsonFactory.create();
/*  46 */       TransferInfo transferInfo = (TransferInfo)json.fromJson(read, TransferInfo.class);
/*  47 */       AggDmoVO[] sourceVOs = getAggDmoVOs(transferInfo);
/*  48 */       if (sourceVOs == null || sourceVOs.length == 0) {
/*  49 */         return null;
/*     */       }
/*  51 */       IPfExchangeService service = (IPfExchangeService)ServiceLocator.find(IPfExchangeService.class);
/*  52 */       AggOprepVO[] destVOs = (AggOprepVO[])service.runChangeDataAry("55C2", "55D2", sourceVOs, null);
/*  53 */       for (AggOprepVO destVO : destVOs) {
/*  54 */         for (int i = 0; i < destVO.getChildrenVO().length; i++) {
/*  55 */           destVO.getChildrenVO()[i].setVrowno(Integer.toString((i + 1) * 10));
/*  56 */           destVO.getChildrenVO()[i].setStatus(2);
/*     */         } 
/*     */       } 
/*  59 */       AggOprepVO[] finalvos = batchAdjustAfterChange(sourceVOs, destVOs);
/*  60 */       DefaultBillUtil util = new DefaultBillUtil();
/*  61 */       util.process(finalvos);
/*  62 */       if (finalvos != null && finalvos.length > 0) {
/*     */         
/*  64 */         BillGridOperator operator = new BillGridOperator(transferInfo.getPagecode());
/*  65 */         grids = operator.toBillGrids(finalvos);
/*  66 */         for (BillGrid billgrid : grids) {
/*  67 */           (new OprepScaleUtil()).processItem(billgrid.getBody());
/*     */         }
/*  69 */         Map<String, Object> result = new HashMap<String, Object>();
/*  70 */         result.put("grids", grids);
/*  71 */         if (MMValueCheck.isNotEmpty(grids)) {
/*  72 */           for (BillGrid billGrid : grids) {
/*  73 */             dealGridFlow(billGrid.getHead());
/*  74 */             dealGridFlow(billGrid.getBody());
/*     */           } 
/*     */         }
/*  77 */         return result;
/*     */       } 
/*  79 */     } catch (Exception e) {
/*  80 */       ExceptionUtils.wrapBusinessException(e.getMessage());
/*     */     } 
/*  82 */     return null;
/*     */   }
/*     */   
/*     */   private void dealGridFlow(Grid grid) {
/*  86 */     if (grid != null && grid.getModel() != null && grid.getModel().getRows() != null) {
/*  87 */       for (Row row : grid.getModel().getRows()) {
/*  88 */         Map<String, Cell> values = row.getValues();
/*  89 */         Iterator<Map.Entry<String, Cell>> iterator = values.entrySet().iterator();
/*  90 */         while (iterator.hasNext()) {
/*  91 */           Map.Entry<String, Cell> entry = (Map.Entry)iterator.next();
/*  92 */           if (MMValueCheck.isEmpty(((Cell)entry.getValue()).getValue()) && MMValueCheck.isEmpty(((Cell)entry.getValue()).getDisplay()) && ((Cell)entry
/*  93 */             .getValue()).getScale() == -1) {
/*  94 */             iterator.remove();
/*     */           }
/*     */         } 
/*     */       } 
/*     */     }
/*     */   }
/*     */   
/*     */   public AggOprepVO[] batchAdjustAfterChange(AggDmoVO[] srcVOs, AggOprepVO[] destVOs) throws BusinessException {
/* 102 */     AggOprepVO[] bills = (AggOprepVO[])destVOs;
/*     */     
/* 104 */     TransBillCommonProcess commonProcess = new TransBillCommonProcess();
/* 105 */     commonProcess.fillOrgValues(bills);
/*     */     
/* 107 */     commonProcess.fillDeptValues(bills);
/* 108 */     return bills;
/*     */   }
/*     */   
/*     */   private AggDmoVO[] getAggDmoVOs(TransferInfo transferInfo) throws BusinessException {
/* 112 */     AggDmoVO[] aggvos = null;
/* 113 */     Map<String, UFDateTime> idTsHeadMap = getIdTsIndex(transferInfo, "pk_dmo");
/* 114 */     Map<String, UFDateTime> idTsBodyMap = getIdTsIndex(transferInfo, "pk_procedure");
/* 115 */     if (idTsHeadMap.size() == 0) {
/* 116 */       return aggvos;
/*     */     }
/* 118 */     String[] hpks = new String[idTsHeadMap.size()];
/* 119 */     hpks = (String[])idTsHeadMap.keySet().toArray(hpks);
/* 120 */     aggvos = ((IDmoQueryService)ServiceLocator.find(IDmoQueryService.class)).queryAggDmoVOByPk(hpks);
/*     */     
/* 122 */     List<DmoVO> allheadvos = new ArrayList<DmoVO>();
/* 123 */     List<DmoProcedureVO> allbodyvos = new ArrayList<DmoProcedureVO>();
/*     */     
/* 125 */     for (AggDmoVO aggvo : aggvos) {
/* 126 */       allheadvos.add(aggvo.getParentVO());
/* 127 */       List<DmoProcedureVO> newitemvos = new ArrayList<DmoProcedureVO>();
/* 128 */       for (DmoProcedureVO itemvo : aggvo.getItems()) {
/* 129 */         if (MMValueCheck.isNotEmpty(idTsBodyMap) && idTsBodyMap.keySet().contains(itemvo.getPk_procedure())) {
/* 130 */           newitemvos.add(itemvo);
/* 131 */           allbodyvos.add(itemvo);
/*     */         } 
/*     */       } 
/* 134 */       aggvo.setChildrenVO((CircularlyAccessibleValueObject[])newitemvos.toArray(new DmoProcedureVO[0]));
/*     */     } 
/* 136 */     return getAggDmoVOs((DmoVO[])allheadvos.toArray(new DmoVO[0]), (DmoProcedureVO[])allbodyvos.toArray(new DmoProcedureVO[0]), idTsHeadMap, idTsBodyMap);
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   private AggDmoVO[] getAggDmoVOs(DmoVO[] headvos, DmoProcedureVO[] bodyvos, Map<String, UFDateTime> idTsHeadMap, Map<String, UFDateTime> idTsBodyMap) {
/* 142 */     AggDmoVO[] aggvos = new AggDmoVO[headvos.length];
/* 143 */     for (int n = 0; n < aggvos.length; n++) {
/* 144 */       headvos[n].setTs((UFDateTime)idTsHeadMap.get(headvos[n].getPk_dmo()));
/* 145 */       AggDmoVO aggvo = new AggDmoVO();
/* 146 */       aggvo.setParentVO(headvos[n]);
/* 147 */       String pk_dmo = headvos[n].getPk_dmo();
/* 148 */       List<DmoProcedureVO> lbvo = new ArrayList<DmoProcedureVO>();
/* 149 */       if (bodyvos != null) {
/* 150 */         for (DmoProcedureVO bvo : bodyvos) {
/* 151 */           bvo.setTs((UFDateTime)idTsBodyMap.get(bvo.getPk_procedure()));
/* 152 */           if (bvo.getPk_dmo().equalsIgnoreCase(pk_dmo)) {
/* 153 */             lbvo.add(bvo);
/*     */           }
/*     */         } 
/*     */       }
/* 157 */       if (lbvo != null) {
/* 158 */         DmoProcedureVO[] arr = new DmoProcedureVO[lbvo.size()];
/* 159 */         aggvo.setChildrenVO((CircularlyAccessibleValueObject[])lbvo.toArray(arr));
/*     */       } 
/* 161 */       aggvos[n] = aggvo;
/*     */     } 
/* 163 */     return aggvos;
/*     */   }
/*     */ 
/*     */   
/*     */   private Map<String, UFDateTime> getIdTsIndex(TransferInfo transferInfo, String attrcode) {
/* 168 */     Map<String, UFDateTime> idTsMap = new HashMap<String, UFDateTime>();
/* 169 */     TransferData[] data = transferInfo.getData();
/* 170 */     if (data != null && data.length > 0) {
/* 171 */       for (TransferData transferData : data) {
/* 172 */         if ("pk_dmo".equals(attrcode)) {
/* 173 */           PkTsVODTO head = transferData.getHead();
/* 174 */           if (head != null) {
/* 175 */             idTsMap.put(head.getPk(), head.getTs());
/*     */           }
/*     */         } else {
/* 178 */           PkTsVODTO[] bodys = transferData.getBodys();
/* 179 */           for (PkTsVODTO body : bodys) {
/* 180 */             idTsMap.put(body.getPk(), body.getTs());
/*     */           }
/*     */         } 
/*     */       } 
/*     */     }
/* 185 */     return idTsMap;
/*     */   }
/*     */ }


/* Location:              E:\zhuhai_ncc\NCC2111\external\li\\uimmsfc_nccloud.jar!/nccloud/web/mmsfc/operationrep/action/TransFromDmoAction.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.0.7
 */